program hello
    implicit none
    real  f1,ff1,f2,ff2,newton
    external f1,ff1,f2,ff2 !add newton or not: no
    !print *, 'here'
    print *, 'solve x**2+4*x+10=0,root=',newton(f1,ff1),'solve 7*x**4+6*x**3-5*x**2+4*x+3=0,root=',newton(f2,ff2)
    print *,'if root=0, this method is not suitable'
end program

real function newton(f,ff)
    real root, root1
    integer i
    !external f,ff !necessary???
    !print*, 'please input root you guess'
    read(*, *) root1
    i=0
    do while (abs(root-root1) .GE. 0.00001 .AND. i .LT. 50)
         root=root1
         root1=root-f(root)/ff(root)
         i=i+1
    end do
    if (i .LT. 50) then
        newton=root1
    else
        newton=0
    end if
end function

real function f1(x)
    f1=x**2+4*x+10
end function

real function ff1(x)
    ff1=2*x+4
end function

real function f2(x)
    f2=7*x**4+6*x**3-5*x**2+4*x+3
end function

real function ff2(x)
    ff2=28*x**3+18*x**2-10*x+4
end function
